﻿using Android.App;
using Android.OS;
using Xamarin.ActionbarSherlockBinding.App;
using Xamarin.ActionbarSherlockBinding.Views;
using Android.Support.V4.View;
using System.Threading;

namespace Cinemacenter.Droid
{
	[Activity (ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
	public class DetailsActivity : SherlockFragmentActivity
	{
		int movieId;

		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
			OverridePendingTransition (Resource.Animation.pull_in_from_right, Resource.Animation.pull_out_to_left);
			//ActionBar.SetDisplayHomeAsUpEnabled (true);
			Window.SetSoftInputMode (Android.Views.SoftInput.StateAlwaysHidden);
			movieId = Intent.GetIntExtra ("movieId", -1);
			SetContentView (Resource.Layout.DetailsLayout);
			var f = new MovieDetailsFragment ();
			var b = new Bundle ();
			b.PutInt ("movieId", movieId);
			f.Arguments = b;
			SupportFragmentManager.BeginTransaction ().Replace (Resource.Id.vpager_content, f).CommitAllowingStateLoss ();	
		}

		protected override void OnPause ()
		{
			OverridePendingTransition (Resource.Animation.pull_in_from_left,
				Resource.Animation.pull_out_to_right);
			base.OnPause ();
		}

		public override bool OnOptionsItemSelected (IMenuItem item)
		{
			switch (item.ItemId) {
			case Android.Resource.Id.Home:
				Finish ();
				return true;
			}			
			return base.OnOptionsItemSelected (item);
		}
	}
}
